/*
 *  Validator.cs
 *  
 *  Validates the user input.
 *  
 *  Copyright (c) 2009, Richard Bao Labs.
 *  
 *  The contents of this file are subject to the Mozilla Public License
 *  Version 1.1 (the "License"); you may not use this file except in
 *  compliance with the License. You may obtain a copy of the License at
 *  
 *  http://www.mozilla.org/MPL/
 *  
 *  Software distributed under the License is distributed on an "AS IS"
 *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 *  the License for the specific language governing rights and limitations
 *  under the License.
 *  
 *  The Original Code is RichControlLibrary.
 *  
 *  The Initial Developer of the Original Code is Richard Bao Labs.
 *  All Rights Reserved.
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace RichControlLibrary
{
    /// <summary>
    /// Validates the user input.
    /// </summary>
    public abstract class Validator
    {
        /// <summary>
        /// Gets a validator that accepts any user input.
        /// </summary>
        public static readonly EmptyValidator Empty = new EmptyValidator();
        
        /// <summary>
        /// Gets a new instance of the <see cref="NumberValidator"/>.
        /// </summary>
        public static NumberValidator Number
        {
            get { return new NumberValidator(); }
        }

        /// <summary>
        /// Gets a new instance of the <see cref="DigitsValidator"/>.
        /// </summary>
        public static DigitsValidator Digits
        {
            get { return new DigitsValidator(); }
        }

        /// <summary>
        /// Gets a new instance of the <see cref="EnglishLettersValidator"/>.
        /// </summary>
        public static EnglishLettersValidator EnglishLetters
        {
            get { return new EnglishLettersValidator(); }
        }

        /// <summary>
        /// Gets a new instance of the <see cref="EmailAddressValidator"/>.
        /// </summary>
        public static EmailAddressValidator EmailAddress
        {
            get { return new EmailAddressValidator(); }
        }

        /// <summary>
        /// Gets a new instance of the <see cref="PhoneNumberValidator"/>.
        /// </summary>
        public static PhoneNumberValidator PhoneNumber
        {
            get { return new PhoneNumberValidator(); }
        }

        private bool _allowEmpty = true;
        /// <summary>
        /// Gets or sets a <see cref="System.Boolean"/> value that indicates whether empty is acceptable.
        /// </summary>
        public virtual bool AllowEmpty 
        {
            get { return _allowEmpty; }
            set { _allowEmpty = value; }
        }

        /// <summary>
        /// Validates the specified text.
        /// </summary>
        /// <param name="text">The text to validate.</param>
        /// <returns>A <see cref="ValidationResult"/> that contains the validation result.</returns>
        public abstract ValidationResult Validate(string text);

        /// <summary>
        /// Gets a <see cref="System.Boolean"/> value that indicates whether the auto formatting feature 
        /// is supported by this validator.
        /// </summary>
        public abstract bool SupportsAutoFormatting { get; }
    }
}
